import { View } from "../../../../mvc/core/View";
import { LayerManager } from "../../../manager/LayerManager";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { ImagesConst } from "../../../resource/ImagesConst";
import { ObjCreate } from "../../common/ObjCreate";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { CurrentSkillPanel } from "./CurrentSkillPanel";
import { SkillPropRenderer } from "./SkillPropRenderer";
import { ScrollPolicy } from "../../../../../flashx/textLayout/container/ScrollPolicy";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { EffectManager } from "../../../manager/EffectManager";
import { SkillPropItem } from "./SkillPropItem";
import { DataEvent } from "../../../events/DataEvent";
import { SPlayerItem } from "../../../../../Message/Public/SPlayerItem";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { ItemData } from "../../../resource/info/ItemData";
import { SkillCombinationList } from "./SkillCombinationList";
import { SceneRange } from "../../../scene/map/SceneRange";
import { SWFInfo } from "../../../../../com/gengine/resource/info/SWFInfo";
import { UICompomentPool } from "../../../../../com/mui/utils/UICompomentPool";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { Global } from "../../../../../com/gengine/global/Global";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
type int = number;
//class UpgradeCrossSecretSkillPanel
    
    export  class UpgradeCrossSecretSkillPanel extends View
    {
        constructor()
        {
            super();
            this._playerItems = [];
            this._skillPropItems = [];
            this.init();
            layer = LayerManager.uiLayer;
            addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickHandler);
            return;
        }

        /* internal  */init(): void
        {
            LoaderManager.instance.load(ImagesConst.eightyDefenceBg + ".swf", this.onBgResLoaded);
            ObjCreate.createBg(7, 107, 275, 73, this, ImagesConst.RechargeBottom);
            ObjCreate.createBg(30, 105, 235, 2, this, ImagesConst.SplitLine);
            this._addBmp1 = ObjCreate.createBitmap(null, 48, 52, this);
            this._addBmp2 = ObjCreate.createBitmap(null, 110, 52, this);
            this._equalBmp = ObjCreate.createBitmap(null, 175, 50, this);
            this._signBmp = ObjCreate.createBitmap(null, 160, 110, this);
            LoaderHelp.addResCallBack(ResFileConst.crossSecretCopy90, this.onResLoaded);
            this._titleTxt = ObjCreate.createGTextField(Language.getString(27616), 0, 4, 288, 22, this, GlobalStyle.getTextFormatCenter(GlobalStyle.textFormat6));
            this._titleTxt.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMoveMouseDown);
            this._supBtn = ObjCreate.createGButton("", 260, 2, 24, 22, this, "MoveBtn");
            this._supBtn.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMoveMouseDown);
            this._currentSkill = new CurrentSkillPanel();
            this._currentSkill.x = 10;
            this._currentSkill.y = 45;
            addChild(this._currentSkill);
            ObjCreate.createGTextField(Language.getString(27617), 15, 110, 150, 20, this);
            this._linkTxt = ObjCreate.createGTextField("", 185, 110, 150, 20, this);
            this._linkTxt.htmlText = Language.getString(27618);
            this._linkTxt.addEventListener(flash.events.TextEvent.LINK, this.onLinkTxtHandler);
            this._propList = ObjCreate.createTileList(15, 135, 265, 40, this);
            this._propList.columnWidth = 45;
            this._propList.rowHeight = 38;
            this._propList.columnCount = 6;
            this._propList.rowCount = 1;
            this._propList.setStyle("cellRenderer", SkillPropRenderer);
            this._propList.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._propList.verticalScrollPolicy = ScrollPolicy.OFF;
            this.addSkillProp();
            Dispatcher.addEventListener(EventName.UpgradeCrossSecretPropUseUpdate, this.onUpgradeCrossSecretPropUseUpdateHandler);
            Dispatcher.addEventListener(EventName.UpgradeCrossSecretPropCancelSelect, this.onUpgradeCrossSecretPropCancelSelectHandler);
            return;
        }

        /* internal  */onMouseClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            EffectManager.glowFilterUnReg(this);
            return;
        }

        /* internal  */addSkillProp(): void
        {
            var loc1=null;
            this._skillPropItems.splice(0);
            var loc2=0;
            while (loc2 < 6) 
            {
                loc1 = new SkillPropItem();
                this._skillPropItems.push(loc1);
                ++loc2;
            }
            return;
        }

        /* internal  */onUpgradeCrossSecretPropUseUpdateHandler(arg1: DataEvent): void
        {
            var loc2=null;
            var loc3=0;
            if (this._currentSkill && this._currentSkill.isSkill) 
            {
                return;
            }
            var loc1=arg1.data as SPlayerItem;
            if (this._playerItems) 
            {
                loc3 = 0;
                while (loc3 < this._skillPropItems.length) 
                {
                    loc2 = this._skillPropItems[loc3];
                    if (loc2 && loc1 && loc2.playerItem == loc1 && loc2.isUse == false) 
                    {
                        loc2.isUse = true;
                    }
                    ++loc3;
                }
            }
            this._propList.dataProvider = new DataProvider(this._skillPropItems);
            return;
        }

        /* internal  */onUpgradeCrossSecretPropCancelSelectHandler(arg1: DataEvent): void
        {
            var loc2=null;
            var loc3=0;
            var loc1=arg1.data as ItemData;
            if (this._skillPropItems) 
            {
                loc3 = 0;
                while (loc3 < this._skillPropItems.length) 
                {
                    loc2 = this._skillPropItems[loc3];
                    if (loc2 && loc1 && loc2.isUse && loc2.playerItem.itemCode == loc1.itemCode) 
                    {
                        loc2.isUse = false;
                    }
                    ++loc3;
                }
            }
            this._propList.dataProvider = new DataProvider(this._skillPropItems);
            return;
        }

        /* internal  */onLinkTxtHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=0;
            if (this._skillCombinationList == null) 
            {
                this._skillCombinationList = new SkillCombinationList();
            }
            if (this._skillCombinationList.isHide) 
            {
                loc1 = SceneRange.display.height - this._skillCombinationList.height - 200;
                this._skillCombinationList.show(this.x, loc1);
            }
            else 
            {
                this._skillCombinationList.hide();
            }
            EffectManager.glowFilterUnReg(this._linkTxt);
            return;
        }

        /* internal  */onBgResLoaded(arg1: SWFInfo): void
        {
            this._bg = UICompomentPool.getUICompoment(ScaleBitmap) as ScaleBitmap;
            this._bg.bitmapData = arg1.bitmapData.clone();
            this._bg.createDisposeChildren();
            this._bg.scale9Grid = new Object /* flash.geom.Rectangle */(100, 50, 68, 74);
            this._bg.width = 295;
            this._bg.height = 188;
            addChildAt(this._bg, 0);
            return;
        }

        /* internal  */onResLoaded(): void
        {
            this._addBmp1.bitmapData = GlobalClass.getBitmapData(ImagesConst.crossSecretCopy90Add);
            this._addBmp2.bitmapData = GlobalClass.getBitmapData(ImagesConst.crossSecretCopy90Add);
            this._equalBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.crossSecretCopy90Equal);
            this._signBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.crossSecretCopy90Sign);
            return;
        }

        /* internal  */onMoveMouseDown(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (arg1.target == this._titleTxt || arg1.target == this._supBtn) 
            {
                this.startDrag();
                Global.stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            }
            return;
        }

        /* internal  */onStageMouseUpHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.stopDrag();
            Global.stage.removeEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }

        public updateSkillProps(arg1: Array<any>): void
        {
            var loc1=null;
            var loc2=0;
            this._playerItems = arg1;
            if (this._playerItems) 
            {
                loc2 = 0;
                while (loc2 < this._skillPropItems.length) 
                {
                    loc1 = this._skillPropItems[loc2];
                    loc1.playerItem = this._playerItems[loc2] as SPlayerItem;
                    ++loc2;
                }
            }
            this._propList.dataProvider = new DataProvider(this._skillPropItems);
            this._ownPropNum = arg1.length;
            this._currentSkill.ownPropNum = this._ownPropNum;
            if (this._ownPropNum >= 6) 
            {
                EffectManager.glowFilterReg(this, [FilterConst.hintIconFilter], 0.3, 6, 3);
                EffectManager.glowFilterReg(this._linkTxt, [FilterConst.hintIconFilter], 0.3, 6, 3);
            }
            return;
        }

        public updateSkillCd(arg1: Array<any>): void
        {
            if (this._currentSkill) 
            {
                this._currentSkill.updateSkillCd(arg1);
            }
            return;
        }

        public stageResize(): void
        {
            this.x = SceneRange.display.width - 575;
            this.y = SceneRange.display.height - 200;
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.stageResize();
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            if (this._currentSkill) 
            {
                this._currentSkill.resetSkill();
            }
            if (this._skillCombinationList) 
            {
                this._skillCombinationList.hide();
            }
            if (this._propList) 
            {
                this.addSkillProp();
                this._propList.dataProvider = new DataProvider(this._skillPropItems);
            }
            return;
        }

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_supBtn: GButton;

        /* internal */ /* var */_addBmp1: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_addBmp2: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_equalBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_signBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_titleTxt: GTextFiled;

        /* internal */ /* var */_currentSkill: CurrentSkillPanel;

        /* internal */ /* var */_propList: GTileList;

        /* internal */ /* var */_skillCombinationList: SkillCombinationList;

        /* internal */ /* var */_playerItems: Array<any>;

        /* internal */ /* var */_skillPropItems: Array<any>;

        /* internal */ /* var */_linkTxt: GTextFiled;

        /* internal */ /* var */_ownPropNum: int;
    }
